﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace SensorNetworkUI
{
    public partial class _Default : System.Web.UI.Page
    {

        protected void Submit_Click(object sender, EventArgs e)
        {





            try
            {




             //   UserDataStructure refe = Global.users[Global.users.IndexOf(new UserDataStructure(loginname.Text))];
                UserDataStructure refe = new UserDataStructure(loginname.Text);
                
                     refe = Global.users.Lookup(loginname.Text);
                


                if (refe.Password.Equals(pass.Text))
                {

                    Session["username"] = refe;
                    SessionManager.Username = refe;
                    refe.GetNetworks();
                    refe.PopulateNetworks();
                    Response.Redirect("~/start.aspx");


                }
                else
                {

                    CustomValidator1.ErrorMessage = "Password Mismatch";
                }


            }
            catch(UserNotFoundException)
            {
                CustomValidator1.ErrorMessage = "Invalid Username";
                CustomValidator1.IsValid = false;

                
            }




        }

        protected void Page_Load_login(object sender, EventArgs e)
        {

            Session["username"] = null;
        }

     

        
    }
}
